package com.mrcode.neptuneproject.controller;

import com.mrcode.neptuneproject.common.Result;
import com.mrcode.neptuneproject.domain.req.ChatInfoReq;
import com.mrcode.neptuneproject.service.ChatGptService;
import com.mrcode.neptuneproject.service.ErnieBotService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author YSH
 * @Date 2023/5/31 19:02
 * @Version 1.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/chat")
public class ChatController {

    private final ChatGptService chatGptService;
    private final ErnieBotService ernieBotService;

    /**
     * 调用chat GPT API进行问题回答
     *
     * @param req ChatInfoReq
     * @return Result
     */
    @PostMapping("/get/gpt/answer")
    public Result<String> getChatAnswer(@RequestBody ChatInfoReq req) {
        return chatGptService.getChatGptAnswer(req.getPrompt());
    }

    /**
     * 调用ErnieBot API进行问题回答
     *
     * @param req ChatInfoReq
     * @return Result
     */
    @PostMapping("/get/ernie/answer")
    public Result<String> getErnieBotAnswer(@RequestBody ChatInfoReq req) {
        return ernieBotService.getErnieBotAnswer(req.getPrompt());
    }

}
